<!DOCTYPE html>
<html>

<head lang="en">
    <title>搜索</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script>
        $(function () {


            //获取关键字
            var keyword = getUrlParam("keyword");

            //当前页
            var currentPage = 1;
            //存储的容器
            var travelsData = [];

            //总页数
            var pages;
            //是否查询中的标记
            var loading = false;

            function query() {
                //如果正在查询中,就不去查询了
                if (loading) {
                    return;
                }
                //设置为正在查询的状态
                loading = true;

                //携带关键字做查询所有游记
                $.get("/travels", {keyword: keyword, pageSize: 2, currentPage: currentPage}, function (data) {

                    $.merge(travelsData, data.list);
                    var ret = {"list": travelsData};
                    console.log(ret.list[0].coverUrl);
                    //渲染数据
                    $(".searchTravel").renderValues(ret, {
                        getHref: function (item, value) {
                            var href = $(item).data("href");
                            $(item).prop("href", href + value);
                        }
                    });
                    //当前页加1
                    currentPage++;
                    //总页数
                    pages = data.pages;
                    //设置为没有在查询的状态
                    loading = false;
                }, 'json');

            }

            query();

            //给window绑定滚动事件
            $(window).scroll(function () {
                //判断是否滚动到底部(屏幕高度+html滚动上去隐藏的高度>=html文档的高度)
                if ($(window).height() + $(document).scrollTop() + 1 >= $(document).height()) {
                    //如果当前页>总页数就不查询了,如果<=就去查询
                    if (currentPage <= pages) {
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '亲,已经到底了!',
                            autoClose: 1500
                        });
                    }
                }
            })

        })
    </script>

</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10" align="center">
            <span>搜索结果&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span>
        </div>

    </div>
</div>

<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
    <li class="nav-item">
        <a class="nav-link" data-toggle="pill" href="#travels">相关游记</a>
    </li>
</ul>

<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="travels">
        <div class="container searchTravel">
            <div class="row hot" render-loop="list">
                <div class="col-6">
                    <a data-href="/travelContent.html?id=" render-fun="getHref" render-key="list.id">
                        <img render-src="list.coverUrl">
                        <p render-html="list.title"></p>
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>


</body>

</html>